import fetch from '../config/fetch'
import { getStore } from '../config/mUtils'

/**
 * web端登录
 */

export const loginWeb = () => fetch({
  url: 'login/v1',
  method: "post",
  data: { appId: "education", account: "13612345678", password: "123456" }
});

/**
 * web端登录
 */

export const login = (code) => fetch({
  url: 'wxPublic/v1/' + code,
  method: "get",
  data: { appId: "education"}
});

// --------------------------------------------------------

/**
 * 获取课程详细信息   -- course.vue
 */
export const getCourseDetail = (token, courseId) => fetch({
  url: 'course/v1/' + courseId + '/addBrowseHistory',
  method: "get",
  token: token,
});

/**
 * 系统配置
 */
export const getConfigAll = (token) => fetch({
  url: 'config/v1/all',
  method: "get",
  token: token,
});

/**
 * 获取浏览记录
 * browseType: 'COURSE' / 'ALBUM'
 */
export const getHistoryRecord = (token, browseType = 'COURSE', pageNumber = 1, pageSize = 20) => fetch({
  url: 'browseHistory/v1/owner',
  method: "get",
  data: { browseType: browseType, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 收入
 */
export const incomeRecord = (token) => fetch({
  url: 'bill/v1/incomeStatistics',
  method: "get",
  data: {},
  token: token,
});

/**
 * 获取账单列表
 */
export const getBillRecord = (token) => fetch({
  url: 'bill/v1/owner',
  method: "get",
  data: {},
  token: token,
});

/**
 * 用户申请提现
 */
export const drawCash = (token, money) => fetch({
  url: 'drawCash/v1',
  method: "post",
  data: {
    "description": "string",
    "money": money,
    "pageNumber": 0,
    "pageSize": 0,
    "remarks": "string",
    "status": "REVIEW"
  },
  token: token,
});

/**
 * 用户申请提现列表
 */
export const drawCashList = (token, money) => fetch({
  url: 'drawCash/v1/owner',
  method: "post",
  data: {
    "description": "string",
    "money": money,
    "pageNumber": 0,
    "pageSize": 0,
    "remarks": "string",
    "status": "REVIEW"
  },
  token: token,
});

/**
 * 获取课程列表-分页
 */
export const getCourseList = (token, pageNumber, pageSize = 20) => fetch({
  url: 'course/v1',
  method: "get",
  data: { "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 获取分类下的课程列表-分页
 */
export const getCategoryCourseList = (token, classId, pageNumber, pageSize = 20) => fetch({
  url: 'course/v1',
  method: "get",
  data: { "classId": classId, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 点赞
 */
export const postPraise = (token, targetId, targetOwnerId, pageNumber, pageSize = 20) => fetch({
  url: 'praise/v1',
  method: "post",
  data: {
    "pageNumber": pageNumber,
    "pageSize": pageSize,
    "targetId": targetId,
    "targetOwnerId": targetOwnerId,
    "targetType": "COURSE"
  },
  token: token,
});

/**
 * 取消点赞
 */
export const postCancelPraise = (token, targetId) => fetch({
  url: 'praise/v1/' + targetId,
  method: "delete",
  data: {},
  token: token,
});

/**
 * 获取课程的评论信息
 */
export const getComment = (token, courseId, pageNumber, pageSize = 20) => fetch({
  url: 'comment/v1',
  method: "get",
  data: { "targetId": courseId, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 对课程进行评论
 */
export const postComment = (token, courseId, targetOwnerId, content) => fetch({
  url: 'comment/v1',
  method: "post",
  data: { "targetId": courseId, "targetOwnerId": targetOwnerId, "targetType": "COURSE", "content": content },
  token: token,
});


/**
 * 根据名称模糊查询专栏 列表
 */
export const selectAlbum = (token, content, pageNumber, pageSize = 20, ) => fetch({
  url: 'album/v1',
  method: "get",
  data: { "name": content, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 获取自己的所有积分记录   --integralRecord.vue
 */
export const getscoreRecord = (token) => fetch({
  url: 'score/v1/owner',
  method: "get",
  data: {},
  token: token,
});

/**
 * 获取自己收入的积分记录  --integralRecord.vue
 */
export const getIncomeRecord = (token, pageNumber = 1, pageSize = 20) => fetch({
  url: 'score/v1/owner',
  method: "get",
  data: { "type": "ADD", "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 获取自己消费的所有积分记录
 */
export const getConsumerRecord = (token, pageNumber = 1, pageSize = 20) => fetch({
  url: 'score/v1/owner',
  method: "get",
  data: { "type": "REDUCE", "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 获取用户直接邀请用户-直接同学 可根据电话号码查询
 */
export const getClassmates = (token, pageNumber, phone, pageSize = 20) => fetch({
  url: 'user/v1/invite',
  method: "get",
  data: { "phone": phone, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

/**
 * 获取用户间接邀请用户-间接同学 可根据电话号码查询
 */
export const getIndirectClassmates = (token, pageNumber, phone, pageSize = 20) => fetch({
  url: 'user/v1/indirectInvite',
  method: "get",
  data: { "phone": phone, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});

// -------------------------------------------------

/**
 * 获取专栏 列表 --home.vue
 */
export const getAlbumList = (token, pageNumber, pageSize = 20) => fetch({
  url: 'album/v1',
  method: "get",
  data: { "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});


/**
 * 获取登录用户信息 --home.vue
 */
export const getUserInfo = (token) => fetch({
  url: 'user/v1',
  method: "get",
  data: {},
  token: token,
});


/**
 * 获取页面所有banner --home.vue
 */
export const getBanner = (token) => fetch({
  url: 'banner/v1/all',
  method: "get",
  data: {},
  token: token,
});


/**
 * 获取所有课程分类信息 --home.vue  --category.vue
 */

export const getCategory = (token) => fetch({
  url: 'courseClass/v1/all',
  method: "get",
  token: token,
});

/**
 * 获取某一个专栏信息   --courseList.vue
 */
export const getAlbumDetail = (token, albumId) => fetch({
  url: 'album/v1/' + albumId + '/addBrowseHistory',
  method: "get",
  data: {},
  token: token,
});

/**
 * 查询一个专栏下的所有课程  --courseList.vue
 */
export const getAlbumCourseList = (token, albumId, pageNumber = 1, pageSize = 20) => fetch({
  url: 'course/v1',
  method: "get",
  data: { "albumId": albumId, "pageNumber": pageNumber, "pageSize": pageSize },
  token: token,
});


/**
 * 购买vip订单  --upgrade.vue
 */
export const upgrade2Vip = (token, vipPriceId, vipPrice, score) => fetch({
  url: 'order/v1',
  method: "post",
  data: { "targetId": vipPriceId, "targetType": "VIP", "originalPrice": vipPrice, "score": score },
  token: token,
});


/**
 * 获取所有vip定价信息 --upgrade.vue
 */
export const getVipInfo = (token) => fetch({
  url: 'vipPrice/v1/all',
  method: "get",
  data: {},
  token: token,
});


/**
 * 获取排行榜   --integralList.vue
 */
export const getRankList = (token, size = 10) => fetch({
  url: 'user/v1/score/rank',
  method: "get",
  data: { "size": size },
  token: token,
});

/**
 * 获取自己的积分排名  --integralList.vue
 */
export const getscore = (token) => fetch({
  url: 'user/v1/owner/rank',
  method: "get",
  data: {},
  token: token,
});